home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / SAT 2.1.2 / Collision ⁄⁄⁄ ƒ / customized SAT.p < prev   
Encoding:
Text File  |  1994-07-02  |  9.3 KB  |  208 lines  |  [TEXT/PJMM]

  1. unit SAT;
  2.  
  3. interface
  4.  
  5.     type
  6.         {BMPtr = ^BitMap;}
  7.  
  8.         FacePtr = ^Face;
  9.         Face = record
  10.                 colorData: Ptr;
  11.                 resNum: integer;
  12.                 iconMask: BitMap;
  13.                 rowBytes: integer;
  14.                 next: FacePtr;
  15.                 maskRgn: RgnHandle;
  16.             end;
  17.  
  18.         SpritePtr = ^Sprite;
  19.         Sprite = record
  20. { Variables that you should change as appropriate }
  21.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  22.                 position: Point;
  23.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  24.                                         {hotRect is set by you. hotRect2 is offset to the current position.}
  25.                 face: FacePtr; { Pointer to the Face (appearance) to be used. }
  26.                 task: ProcPtr; { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  27.                 hitTask: ProcPtr; { Callback in collisions. }
  28.                 destructTask: ProcPtr; { Called when a sprite is disposed. (Usually nil.) }
  29. { SAT variables that you shouldn't change: }
  30.                 oldpos: Point;                {The 'task' routine is not allowed to change this! }
  31.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  32.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  33. {Variables for internal use by the sprites. I have edited them, to add fixed-point postions!}
  34. {Since we have edited the record, we must SetSpriteSize immediately}
  35. {after initializing (before any sprites are created)!}
  36.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  37.                 speed: Point; { Can be used for speed, but not necessarily. }
  38.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  39.                 fixedPos: Point; {Position * 16}
  40.             end;
  41.  
  42. {Type for SATs pattern utilities.}
  43.     type
  44.         SATPattern = record
  45.                 patternType: integer; {1 = Pattern, PatHandle, 2 = PixPat, PixPatHandle}
  46.                 thePat: PixPatHandle; {or PatHandle}
  47.             end; {record}
  48.         SATPatPtr = ^SATPattern;
  49.         SATPatHandle = ^SATPatPtr;
  50.  
  51. {Update list. Used internally}
  52.         UpdatePtr = ^UpdateRec;
  53.         UpdateRec = record
  54.                 updateRect: Rect;
  55.                 next: UpdatePtr;
  56.             end;
  57.  
  58. {The globals record. Some fields are important for you. These are marked with *}
  59.         SATglobalsRec = record
  60.                 wind: WindowPtr;                            {*The window that SAT draws in. }
  61.                 offSizeH, offSizeV: integer;                    {*Offscreen size, used to limit sprite positions}
  62.                 offScreen: GrafPtr;                            {*Offscreen image }
  63.                 backScreen: GrafPtr;                        {*Background image }
  64.                 offScreenGD, BackScreenGD: GDHandle;    {GDevices for offScreen and backScreen.}
  65.  
  66.                 ox, oy: longint;                                {Internal}
  67.                 pict, bwpict: integer;                        {PICT id's}
  68.                 fitThePICTs: boolean;                        {Resize PICTs to fit?}
  69.                 sorting: integer;                                {Chosen sorting}
  70.                 collision: integer;                            {Chosen collision handling}
  71.                 searchWidth: integer;                        {Chosen search width}
  72.                 device: GDHandle;                            {Chosen screen}
  73.                 screen: PixMapHandle;                        {Internal}
  74.                 bounds: Rect;                                    {Internal}
  75.                 initDepth: Integer;                            {*Depth at last icon initialization}
  76.                 synchHook: ProcPtr;                            {Synch procedure}
  77.                 sRoot: SpritePtr;                                {Sprite list root}
  78.                 updateRoot: UpdatePtr;                        {Update list root}
  79.                 anyMonsters: Boolean;                        {*False when no sprites with kind < -1 are active }
  80.  
  81.                 ditherOff: CGrafPtr;                            {Internal}
  82.                 ditherOffGD: GDHandle;                        {Internal}
  83.                 iconPort: CGrafPtr;                            {Internal}
  84.                 iconPortGD: GDHandle;                        {Internal}
  85.                 iconPort2: CGrafPtr;                        {Internal}
  86.                 iconPort2GD: GDHandle;                        {Internal}
  87.                 bwIconPort: GrafPtr;                         {Internal}
  88.             end;
  89.  
  90. {Configuration types: VPositionSort and KindCollision are defaults.}
  91.     const
  92. {Sorting options}
  93.         kVPositionSort = 0;
  94.         kLayerSort = 1;
  95.         kNoSort = 2;
  96. {Collision detection options}
  97.         kKindCollision = 0;
  98.         kForwardCollision = 1;
  99.         kBackwardCollision = 2;
  100.         kNoCollision = 3;
  101.  
  102.     var
  103. {$J+}
  104.         gSAT: SATglobalsRec;                {Most globals in a record. See above.}
  105.         faceRoot: FacePtr;                    {Root of face list}
  106.         colorFlag: Boolean;                    {True if color QuickDraw is available.}
  107.         gSATSoundErrorProc: ProcPtr;        {Pointer to procedure to call on sound error.}
  108. {$J-}
  109.  
  110. {Initializing and customizing}
  111.     procedure ConfigureSAT (PICTfit: boolean; newSorting, newCollision, searchWidth: integer);
  112.     procedure InitSAT (pictID, bwpictID, Xsize, Ysize: integer);
  113.     procedure CustomInitSAT (pictID, bwpictID: integer; SATdrawingArea: Rect; {}
  114.                                     preloadedWind: WindowPtr; chosenScreen: GDHandle; useMenuBar, {}
  115.                                     centerDrawingArea, fillScreen, dither4bit, beSmart: Boolean);
  116. {Maintainance, background manipulation etc.}
  117.     function SATDepthChangeTest: Boolean;
  118.     procedure SATDrawPICTs (pictID, bwpictID: integer);
  119.     procedure PeekOffscreen;
  120. {Drawing}
  121.     procedure SATPlotFace (theFace: FacePtr; theGrafPtr: GrafPtr; theGDevice: GDHandle;{}
  122.                                     where: Point; fast: boolean);
  123.     procedure SATPlotFaceToScreen (theFace: FacePtr; where: Point; fast: boolean);
  124.     procedure SATCopyBits (src, dest: GrafPtr; destGD: GDHandle; {}
  125.                                     srcRect, destRect: Rect; fast: Boolean);
  126.     procedure SATCopyBitsToScreen (src: GrafPtr; srcRect, destRect: Rect; fast: Boolean);
  127.     procedure SATBackChanged (r: Rect); {Tell SAT about changes in backScreen}
  128. {SetPort replacements}
  129.     procedure SATGetPort (var port: GrafPtr; var device: GDHandle);
  130.     procedure SATSetPort (port: GrafPtr; device: GDHandle);
  131.     procedure SATSetPortOffScreen; {Use before using QuickDraw on offScreen}
  132.     procedure SATSetPortBackScreen; {Use before using QuickDraw on backScreen}
  133.     procedure SATSetPortScreen; {Use to set port to gSAT.wind}
  134. {Sprite handling}
  135.     function GetFace (resNum: integer): FacePtr;
  136.     procedure DisposeFace (theFace: FacePtr);
  137.     function NewSprite (kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  138.     function NewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  139.     procedure KillSprite (who: Spriteptr);
  140. {Animating}
  141.     procedure RunSAT (fast: Boolean); {The heart of the whole package!}
  142. {Special functions for advanced programmers}
  143.     procedure SATInstallSynch (theSynchProc: ProcPtr);
  144.     procedure SATInstallEmergency (theEmergencyProc: ProcPtr);
  145.     procedure SATSetSpriteRecSize (theSize: longint);
  146.     procedure SkipSAT;
  147.     procedure KillSAT; {Dispose of offscreen buffers to allow re-init}
  148. {New procedures}
  149.     procedure SetPortMask (theFace: FacePtr);
  150.     procedure SetPortFace (theFace: FacePtr);
  151.     procedure SetPortFace2 (theFace: FacePtr);
  152.     function NewFace (faceBounds: Rect): FacePtr;
  153.     procedure ChangedFace (theFace: FacePtr);
  154.     procedure SATSetStrings (ok, yes, no, quit, memerr, noscreen, nopict, nowind: Str255);
  155.     function TrapAvailable (theTrap: Integer): Boolean;
  156.     function SATGetCicn (cicnId: integer): CIconHandle;
  157.     procedure SATPlotCicn (theCicn: CIconHandle; dest: GrafPtr; destGD: GDHandle; r: Rect); {Borde jag lägga till device?}
  158.     procedure SATDisposeCicn (theCicn: CIconHandle);
  159. {Offscreen - use only if you need an *extra* offscreen buffer. These calls are likely to change in the future!}
  160.     procedure SATMakeOffscreen (var portP: GrafPtr; rectP: Rect; var retGDevice: GDHandle); {Make offscreen buffer in current screen depth and CLUT.}
  161.     procedure SATDisposeOffScreen (var portP: GrafPtr; theGDevice: GDHandle); {Get rid of offscreen}
  162.     function CreateOffScreen (bounds: Rect; depth: Integer; colors: CTabHandle; var retPort: CGrafPtr; var retGDevice: GDHandle): OSErr; {From Principia Offscreen - color only}
  163.     procedure DisposeOffScreen (doomedPort: CGrafPtr; doomedGDevice: GDHandle);{From Principia Offscreen - color only}
  164.  
  165. {Utilities}
  166.     procedure DrawInt (i: integer);
  167.     procedure DrawLong (l: longint);
  168.     function Rand (n: integer): integer;
  169.     function Rand10: integer;
  170.     function Rand100: integer;
  171.     procedure ReportStr (str: str255);
  172.     function QuestionStr (str: str255): Boolean;
  173.     function SATFakeAlert (s1, s2, s3, s4: Str255; nButtons, defButton, cancelButton: integer;{}
  174.                                     t1, t2, t3: Str255): integer;
  175.     procedure CheckNoMem (p: Ptr); {If the Ptr is nil, out of memory emergency exit}
  176.     procedure SetMouse (where: point);
  177. {Pattern utilities}
  178.     procedure SATPenPat (SATpat: SATPatHandle);
  179.     procedure SATBackPat (SATpat: SATPatHandle);
  180.     function SATGetPat (patID: integer): SATPatHandle;
  181.     procedure SATDisposePat (SATpat: SATPatHandle);
  182. {Menu bar utilities}
  183.     procedure ShowMBar;
  184.     procedure HideMBar (wind: WindowPtr);
  185. {Sound}
  186.     procedure SATSoundInit; {Called from InitSAT}
  187.     procedure SATSoundPlay (TheSound: Handle; Priority: integer; CanWait: boolean);
  188.     procedure SATSoundEvents; {Call this once in a while when not calling RunSAT often}
  189.     procedure SATSoundShutup; {Silence, dispose of sound channel}
  190.     procedure SATSoundOn;
  191.     procedure SATSoundOff;
  192.     function SATSoundDone: Boolean; {Any sound going on ?}
  193.     function SATGetSound (sndId: integer): handle;        { To load a sound and get a handle for SATSoundPlay }
  194.     function SATGetNamedSound (name: Str255): Handle; { Same but using resource names }
  195.     procedure SATDisposeSound (theSnd: handle);
  196. {Multi-channel sound routines}
  197.     function SATSoundInitChannels (num: integer): integer;
  198.     function SATSoundDoneChannel (chanNum: integer): Boolean;
  199.     procedure SATSoundPlayChannel (theSound: Handle; chanNum: integer);
  200.     procedure SATSoundReserveChannel (chanNum: integer; reserve: Boolean);
  201.     procedure SATSoundShutupChannel (chanNum: integer);
  202.     procedure SATPreloadChannels;
  203. {Experimental, likely to be renamed/removed/changed:}
  204.     procedure SATSoundPlay2 (theSound: Handle; priority: integer; canWait, skipIfSame: Boolean);
  205.     procedure SATSoundPlayEasy (theSound: handle; canWait: boolean);
  206.  
  207. implementation
  208. end.